/* 
 * File:   IO.cpp
 * Author: Henrique
 * 
 * Created on 26 de Março de 2010, 11:26
 */

#include "IO.h"


IO::IO() {
}

IO::IO(const IO& orig) {
}

IO::~IO() {
}

void IO::saida(double* m)
{
    double* temp = m;
    for (int i = 0; i < 26; i++) {
        std::cout << m[i] << " " << (char)(i+(int)'a') << std::endl;
    }
}

std::vector<std::string> IO::entrada(int argc, char *argv[]) {

    
   std::string arquivo = "";

    int option_char;

    while ((option_char = getopt(argc, argv, "a:")) != EOF) {
        switch (option_char) {
            case 'a': arquivo = optarg;
                break;

            case '?':
                break;
        } /* -----  end switch  ----- */
    }
    /*TESTE AQUI IO*/
 //   std::string path = "C:\\Users\\Henrique\\Desktop\\atrib.tiny";
    std::ifstream stream;
    stream.open(arquivo.c_str(), std::ifstream::in);

    std::vector<std::string> instrucoes;

    if (stream.is_open()) {
        while (!stream.eof()) {

            std::string linha;
            std::getline(stream, linha);
            

            for (int i = 0; i < linha.size(); i++) {
                char ch = linha.at(i);

                if(ch == ' '){
                    linha.erase(0,1);
                    i--;
                }
                else
                    break;

            }

            instrucoes.push_back(linha);
          
        }
        stream.close();
    } else {
        std::cout << "Erro no arquivo!!" << std::endl;
    }
  return instrucoes;
}

